package com.newworld.dmsapp2.ui.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.bean.InitOperation;
import com.newworld.dmsapp2.util.StringUtil;

public class CustomButtonItem extends LinearLayout{
	LayoutInflater mInflater;
	View customButtonItem;
	LinearLayout ly;
	Button btn1,btn2,btn3;
	
	Context context;
	public CustomButtonItem(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}


	private List<InitOperation> buttonItem = new ArrayList<InitOperation>();
	private boolean issureAccept;
	public LinearLayout getCustomButtonItem(Context context,List<InitOperation> buttonItem,boolean  issureAccept ) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.buttonItem = buttonItem;
		this.issureAccept = issureAccept;
		
		for(int i = 0;i < buttonItem.size();i++){//催单不显示底部按钮
			if(StringUtil.isStringEqual(buttonItem.get(i).getOperationName(), "催单")){
				buttonItem.remove(i);
			}
		}
		
		mInflater = LayoutInflater.from(context);
		customButtonItem = mInflater.inflate(R.layout.view_custom_buttonitem, null);
		initView(customButtonItem);
		return (LinearLayout) customButtonItem;
	}

	private void initView(View customTextItem) {
		switch (buttonItem.size()) {
		case 1:
			ly = (LinearLayout)customButtonItem.findViewById(R.id.custom_button_ly1);
			ly.setVisibility(View.VISIBLE);
			btn1 = (Button) customButtonItem.findViewById(R.id.custom_button_ly1_btn1);
			btn1.setText(buttonItem.get(0).getOperationName());
			if(issureAccept){
				btn1.setBackground(getResources().getDrawable(
						R.drawable.button_blue_press));
				btn1.setEnabled(false);
			}
			
			/*btn_start_repair.setBackground(getResources().getDrawable(
					R.drawable.button_blue));
			btn_start_repair.setEnabled(true);*/
			break;
		case 2:
			ly = (LinearLayout)customButtonItem.findViewById(R.id.custom_button_ly2);
			ly.setVisibility(View.VISIBLE);
			btn1 = (Button) customButtonItem.findViewById(R.id.custom_button_ly2_btn1);
			btn2 = (Button) customButtonItem.findViewById(R.id.custom_button_ly2_btn2);
			btn1.setText(buttonItem.get(0).getOperationName());
			btn2.setText(buttonItem.get(1).getOperationName());
			break;
		case 3:
			ly = (LinearLayout)customButtonItem.findViewById(R.id.custom_button_ly3);
			ly.setVisibility(View.VISIBLE);
			btn1 = (Button) customButtonItem.findViewById(R.id.custom_button_ly3_btn1);
			btn2 = (Button) customButtonItem.findViewById(R.id.custom_button_ly3_btn2);
			btn3 = (Button) customButtonItem.findViewById(R.id.custom_button_ly3_btn3);
			btn1.setText(buttonItem.get(0).getOperationName());
			btn2.setText(buttonItem.get(1).getOperationName());
			btn3.setText(buttonItem.get(2).getOperationName());
			break;
		default:
			break;
		}
	}
	
	public void setButtonOnClick(View.OnClickListener listener1) {
		btn1.setOnClickListener(listener1);
	}

	public void setButtonOnClick(View.OnClickListener listener1,
			View.OnClickListener listener2) {
		btn1.setOnClickListener(listener1);
		btn2.setOnClickListener(listener2);
	}

	public void setButtonOnClick(View.OnClickListener listener1,
			View.OnClickListener listener2, View.OnClickListener listener3) {
		btn1.setOnClickListener(listener1);
		btn2.setOnClickListener(listener2);
		btn3.setOnClickListener(listener3);
	}
	
	
	
	
}
